<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DOM测试</title>
</head>
<body>
<input type="text" id="i1"><br>
<input type="text" id="i2"><br>
<button onclick="f1('+')">加</button>
<button onclick="f1('-')">减</button>
<button onclick="f1('*')">乘</button>
<button onclick="f1('/')">除</button>
<h4>显示结果:<span class="re"></span></h4>
</body>
<script>
  function f1(a) {
    let i1 = document.querySelector('#i1');
    console.log(i1.value);
    let i2 = document.querySelector('#i2');
    console.log(i2.value);
    let re = document.querySelector('.re');
    switch (a){
      case '+':
        re.innerHTML=parseInt(i1.value)+parseInt(i2.value);
        break;
      case '-':
        re.innerHTML=parseInt(i1.value)-parseInt(i2.value);
        break;
      case '*':
        re.innerHTML=parseInt(i1.value)*parseInt(i2.value);
        break;
      case '/':
        if(parseFloat(i2.value)!=0){
          re.innerHTML=parseInt(i1.value)/parseInt(i2.value);
        }else {
          alert('除数不能为0');
        }
    }

  }
</script>
</html>